package cn.itcast.controller;

import cn.itcast.constant.MessageConstant;
import cn.itcast.entity.Result;
import cn.itcast.service.SmsService;
import com.alibaba.dubbo.config.annotation.Reference;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionContext;

/**
 * @Author: ZHT
 * @Dtae: 2021/11/16 13:23
 * @Version: 1.0
 */

@Slf4j
@RestController
@RequestMapping(path = "/sms")
@CrossOrigin
public class SmsController {

    @Reference
    private SmsService smsService;


    @PostMapping("/sendLoginCode")
    public Result sms(HttpServletRequest request){

        //System.out.println(phone);
        try {
            // String s = this.smsService.sendSms(phone);
            String s = 123456+"";
            request.getServletContext().setAttribute("s",s);
            System.out.println(request.getServletContext().getAttribute("s"));
            if (null != s) {
                return new Result(true, MessageConstant.SEND_VALIDATECODE_SUCCESS , s);
            }
        } catch (Exception e) {
            //log.error("发送短信验证码失败~ phone = " + phone, e);

        }
        return new Result(true, MessageConstant.SEND_VALIDATECODE_FAIL);
    }

}
